﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Utility;
using Runda.CMS.Common.Entity;
using Runda.CMS.Bll;
using System.Data;

namespace Runda.CMS.Portal.Finiance
{
    public partial class CheckOffsList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {               
                if (Request.QueryString["UserID"] != null && Request.QueryString["UserID"].ToString() != "") {
                    txtUserID.Value = Request.QueryString["UserID"];  
                    BindList(1);
                }               
            }
        }
        private void BindList(int pageindex)
        {
             
            int RecordCount = 0;
            DataTable list = new BillBll().QueryUserPerformanceSummary(" and UserID='" + txtUserID.Value + "'","Year desc ,Month desc",AspNetPager1.PageSize, pageindex, out RecordCount);

            RepeaterUsers.DataSource = list;
            RepeaterUsers.DataBind();
            AspNetPager1.RecordCount = RecordCount;
        }

        protected void RepeaterUsers_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "refersh")
            {
                BindList(1);
            }
        }
       
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindList(AspNetPager1.CurrentPageIndex);
        }

        protected void RepeaterUsers_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Label RealizeFundsTotal = e.Item.FindControl("RealizeFundsTotal") as Label;
            Label txtYear =e.Item.FindControl("txtYear") as Label;
            Label txtMonth = e.Item.FindControl("txtMonth") as Label;

            if (RealizeFundsTotal != null && txtYear != null && txtMonth != null)
            {
                List<ArmCheckOffsForMonthEntity> list = new ArmCheckOffsForMonthBll().GetAll<ArmCheckOffsForMonthEntity>(" and Month=" + txtMonth.Text + " and Year=" + txtYear.Text + " and UserID='" + Request.QueryString["UserID"] + "'");
                decimal totalFund = 0;
                foreach (ArmCheckOffsForMonthEntity entity in list)
                {
                    totalFund = totalFund+ entity.RealizeFunds;
                }
                RealizeFundsTotal.Text = totalFund.ToString();
            }          
        } 
    }
}
